{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "file = 'data/add_cargo.csv'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "outputs": [
    {
     "data": {
      "text/plain": "       Unnamed: 0 bad_case_name core_word ignore_word           reason_text  \\\n0               0         苹果123        苹果         123  包含数量、价格、包装、尺寸、装卸货等信息   \n1               1     需24米内径装木方        木方       24米内径  包含数量、价格、包装、尺寸、装卸货等信息   \n2               2      9吨铁皮7吨岩棉        铁皮          9吨  包含数量、价格、包装、尺寸、装卸货等信息   \n3               3       在丹江口市边装                        包含数量、价格、包装、尺寸、装卸货等信息   \n4               4          袋装化肥                        包含数量、价格、包装、尺寸、装卸货等信息   \n...           ...           ...       ...         ...                   ...   \n54681       54681    溧阳上兴镇到芜湖九江            溧阳上兴镇到芜湖九江                   无货名   \n54682       54682      电瓶车蛇皮袋4袋                                        多个货物   \n54683       54683        泡沫板和型钢                                        多个货物   \n54684       54684          电线钻头                                        多个货物   \n54685       54685         小电机纸箱       小电机          纸箱  包含数量、价格、包装、尺寸、装卸货等信息   \n\n      reason_id correct_word  is_valid new_core_word  \n0          1001                      1            苹果  \n1          1001                      1            木方  \n2          1001                      1            铁皮  \n3          1001                      1                \n4          1001                      1            化肥  \n...         ...          ...       ...           ...  \n54681      1003                      1                \n54682      1002                      1           电瓶车  \n54683      1002                      1           泡沫板  \n54684      1002                      1            电线  \n54685      1001                      1           小电机  \n\n[54686 rows x 9 columns]",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>Unnamed: 0</th>\n      <th>bad_case_name</th>\n      <th>core_word</th>\n      <th>ignore_word</th>\n      <th>reason_text</th>\n      <th>reason_id</th>\n      <th>correct_word</th>\n      <th>is_valid</th>\n      <th>new_core_word</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>0</td>\n      <td>苹果123</td>\n      <td>苹果</td>\n      <td>123</td>\n      <td>包含数量、价格、包装、尺寸、装卸货等信息</td>\n      <td>1001</td>\n      <td></td>\n      <td>1</td>\n      <td>苹果</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>1</td>\n      <td>需24米内径装木方</td>\n      <td>木方</td>\n      <td>24米内径</td>\n      <td>包含数量、价格、包装、尺寸、装卸货等信息</td>\n      <td>1001</td>\n      <td></td>\n      <td>1</td>\n      <td>木方</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>2</td>\n      <td>9吨铁皮7吨岩棉</td>\n      <td>铁皮</td>\n      <td>9吨</td>\n      <td>包含数量、价格、包装、尺寸、装卸货等信息</td>\n      <td>1001</td>\n      <td></td>\n      <td>1</td>\n      <td>铁皮</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>3</td>\n      <td>在丹江口市边装</td>\n      <td></td>\n      <td></td>\n      <td>包含数量、价格、包装、尺寸、装卸货等信息</td>\n      <td>1001</td>\n      <td></td>\n      <td>1</td>\n      <td></td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>4</td>\n      <td>袋装化肥</td>\n      <td></td>\n      <td></td>\n      <td>包含数量、价格、包装、尺寸、装卸货等信息</td>\n      <td>1001</td>\n      <td></td>\n      <td>1</td>\n      <td>化肥</td>\n    </tr>\n    <tr>\n      <th>...</th>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n    </tr>\n    <tr>\n      <th>54681</th>\n      <td>54681</td>\n      <td>溧阳上兴镇到芜湖九江</td>\n      <td></td>\n      <td>溧阳上兴镇到芜湖九江</td>\n      <td>无货名</td>\n      <td>1003</td>\n      <td></td>\n      <td>1</td>\n      <td></td>\n    </tr>\n    <tr>\n      <th>54682</th>\n      <td>54682</td>\n      <td>电瓶车蛇皮袋4袋</td>\n      <td></td>\n      <td></td>\n      <td>多个货物</td>\n      <td>1002</td>\n      <td></td>\n      <td>1</td>\n      <td>电瓶车</td>\n    </tr>\n    <tr>\n      <th>54683</th>\n      <td>54683</td>\n      <td>泡沫板和型钢</td>\n      <td></td>\n      <td></td>\n      <td>多个货物</td>\n      <td>1002</td>\n      <td></td>\n      <td>1</td>\n      <td>泡沫板</td>\n    </tr>\n    <tr>\n      <th>54684</th>\n      <td>54684</td>\n      <td>电线钻头</td>\n      <td></td>\n      <td></td>\n      <td>多个货物</td>\n      <td>1002</td>\n      <td></td>\n      <td>1</td>\n      <td>电线</td>\n    </tr>\n    <tr>\n      <th>54685</th>\n      <td>54685</td>\n      <td>小电机纸箱</td>\n      <td>小电机</td>\n      <td>纸箱</td>\n      <td>包含数量、价格、包装、尺寸、装卸货等信息</td>\n      <td>1001</td>\n      <td></td>\n      <td>1</td>\n      <td>小电机</td>\n    </tr>\n  </tbody>\n</table>\n<p>54686 rows × 9 columns</p>\n</div>"
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "origin_df = pd.read_csv(file,sep=',')\n",
    "origin_df.fillna(\"\",inplace=True)\n",
    "origin_df"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "outputs": [],
   "source": [],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "outputs": [],
   "source": [],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "outputs": [
    {
     "data": {
      "text/plain": "    错误码     个数\n0  1003  18771\n1  1001  16694\n2  1002  15607\n3  1004   4496\n4  1006    601\n5  1005    111",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>错误码</th>\n      <th>个数</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>1003</td>\n      <td>18771</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>1001</td>\n      <td>16694</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>1002</td>\n      <td>15607</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>1004</td>\n      <td>4496</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>1006</td>\n      <td>601</td>\n    </tr>\n    <tr>\n      <th>5</th>\n      <td>1005</td>\n      <td>111</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = origin_df['reason_id'].str.split('|', expand=True).stack()\n",
    "c = a.value_counts()\n",
    "d = pd.DataFrame(data=c,columns=[\"个数\"]).reset_index().rename(columns={\"index\":\"错误码\"})\n",
    "d"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "outputs": [
    {
     "data": {
      "text/plain": "                                 Unnamed: 0  bad_case_name  core_word  \\\nreason_text                                                             \n包含数量、价格、包装、尺寸、装卸货等信息                  15134          15134      15134   \n包含数量、价格、包装、尺寸、装卸货等信息|多个货物               269            269        269   \n包含数量、价格、包装、尺寸、装卸货等信息|无货名                725            725        725   \n包含数量、价格、包装、尺寸、装卸货等信息|无货名|多个货物             1              1          1   \n包含数量、价格、包装、尺寸、装卸货等信息|货类                   1              1          1   \n包含数量、价格、包装、尺寸、装卸货等信息|错字或拼音               84             84         84   \n危险品/危化品/违禁词                             109            109        109   \n多个货物                                  15212          15212      15212   \n多个货物|包含数量、价格、包装、尺寸、装卸货等信息                99             99         99   \n多个货物|包含数量、价格、包装、尺寸、装卸货等信息|无货名             1              1          1   \n多个货物|无货名                                  6              6          6   \n多个货物|错字或拼音                                6              6          6   \n无货名                                   17744          17744      17744   \n无货名|包含数量、价格、包装、尺寸、装卸货等信息                283            283        283   \n无货名|包含数量、价格、包装、尺寸、装卸货等信息|多个货物             1              1          1   \n无货名|包含数量、价格、包装、尺寸、装卸货等信息|错字或拼音            1              1          1   \n无货名|危险品/危化品/违禁词                           1              1          1   \n无货名|多个货物                                  5              5          5   \n无货名|多个货物|包含数量、价格、包装、尺寸、装卸货等信息             1              1          1   \n无货名|错字或拼音                                 1              1          1   \n货类                                      597            597        597   \n货类|包含数量、价格、包装、尺寸、装卸货等信息                   1              1          1   \n错字或拼音                                  4302           4302       4302   \n错字或拼音|包含数量、价格、包装、尺寸、装卸货等信息               92             92         92   \n错字或拼音|危险品/危化品/违禁词                         1              1          1   \n错字或拼音|多个货物                                5              5          5   \n错字或拼音|多个货物|包含数量、价格、包装、尺寸、装卸货等信息           1              1          1   \n错字或拼音|无货名                                 1              1          1   \n错字或拼音|货类                                  2              2          2   \n\n                                 ignore_word  reason_id  correct_word  \\\nreason_text                                                             \n包含数量、价格、包装、尺寸、装卸货等信息                   15134      15134         15134   \n包含数量、价格、包装、尺寸、装卸货等信息|多个货物                269        269           269   \n包含数量、价格、包装、尺寸、装卸货等信息|无货名                 725        725           725   \n包含数量、价格、包装、尺寸、装卸货等信息|无货名|多个货物              1          1             1   \n包含数量、价格、包装、尺寸、装卸货等信息|货类                    1          1             1   \n包含数量、价格、包装、尺寸、装卸货等信息|错字或拼音                84         84            84   \n危险品/危化品/违禁词                              109        109           109   \n多个货物                                   15212      15212         15212   \n多个货物|包含数量、价格、包装、尺寸、装卸货等信息                 99         99            99   \n多个货物|包含数量、价格、包装、尺寸、装卸货等信息|无货名              1          1             1   \n多个货物|无货名                                   6          6             6   \n多个货物|错字或拼音                                 6          6             6   \n无货名                                    17744      17744         17744   \n无货名|包含数量、价格、包装、尺寸、装卸货等信息                 283        283           283   \n无货名|包含数量、价格、包装、尺寸、装卸货等信息|多个货物              1          1             1   \n无货名|包含数量、价格、包装、尺寸、装卸货等信息|错字或拼音             1          1             1   \n无货名|危险品/危化品/违禁词                            1          1             1   \n无货名|多个货物                                   5          5             5   \n无货名|多个货物|包含数量、价格、包装、尺寸、装卸货等信息              1          1             1   \n无货名|错字或拼音                                  1          1             1   \n货类                                       597        597           597   \n货类|包含数量、价格、包装、尺寸、装卸货等信息                    1          1             1   \n错字或拼音                                   4302       4302          4302   \n错字或拼音|包含数量、价格、包装、尺寸、装卸货等信息                92         92            92   \n错字或拼音|危险品/危化品/违禁词                          1          1             1   \n错字或拼音|多个货物                                 5          5             5   \n错字或拼音|多个货物|包含数量、价格、包装、尺寸、装卸货等信息            1          1             1   \n错字或拼音|无货名                                  1          1             1   \n错字或拼音|货类                                   2          2             2   \n\n                                 is_valid  new_core_word  \nreason_text                                               \n包含数量、价格、包装、尺寸、装卸货等信息                15134          15134  \n包含数量、价格、包装、尺寸、装卸货等信息|多个货物             269            269  \n包含数量、价格、包装、尺寸、装卸货等信息|无货名              725            725  \n包含数量、价格、包装、尺寸、装卸货等信息|无货名|多个货物           1              1  \n包含数量、价格、包装、尺寸、装卸货等信息|货类                 1              1  \n包含数量、价格、包装、尺寸、装卸货等信息|错字或拼音             84             84  \n危险品/危化品/违禁词                           109            109  \n多个货物                                15212          15212  \n多个货物|包含数量、价格、包装、尺寸、装卸货等信息              99             99  \n多个货物|包含数量、价格、包装、尺寸、装卸货等信息|无货名           1              1  \n多个货物|无货名                                6              6  \n多个货物|错字或拼音                              6              6  \n无货名                                 17744          17744  \n无货名|包含数量、价格、包装、尺寸、装卸货等信息              283            283  \n无货名|包含数量、价格、包装、尺寸、装卸货等信息|多个货物           1              1  \n无货名|包含数量、价格、包装、尺寸、装卸货等信息|错字或拼音          1              1  \n无货名|危险品/危化品/违禁词                         1              1  \n无货名|多个货物                                5              5  \n无货名|多个货物|包含数量、价格、包装、尺寸、装卸货等信息           1              1  \n无货名|错字或拼音                               1              1  \n货类                                    597            597  \n货类|包含数量、价格、包装、尺寸、装卸货等信息                 1              1  \n错字或拼音                                4302           4302  \n错字或拼音|包含数量、价格、包装、尺寸、装卸货等信息             92             92  \n错字或拼音|危险品/危化品/违禁词                       1              1  \n错字或拼音|多个货物                              5              5  \n错字或拼音|多个货物|包含数量、价格、包装、尺寸、装卸货等信息         1              1  \n错字或拼音|无货名                               1              1  \n错字或拼音|货类                                2              2  ",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>Unnamed: 0</th>\n      <th>bad_case_name</th>\n      <th>core_word</th>\n      <th>ignore_word</th>\n      <th>reason_id</th>\n      <th>correct_word</th>\n      <th>is_valid</th>\n      <th>new_core_word</th>\n    </tr>\n    <tr>\n      <th>reason_text</th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>包含数量、价格、包装、尺寸、装卸货等信息</th>\n      <td>15134</td>\n      <td>15134</td>\n      <td>15134</td>\n      <td>15134</td>\n      <td>15134</td>\n      <td>15134</td>\n      <td>15134</td>\n      <td>15134</td>\n    </tr>\n    <tr>\n      <th>包含数量、价格、包装、尺寸、装卸货等信息|多个货物</th>\n      <td>269</td>\n      <td>269</td>\n      <td>269</td>\n      <td>269</td>\n      <td>269</td>\n      <td>269</td>\n      <td>269</td>\n      <td>269</td>\n    </tr>\n    <tr>\n      <th>包含数量、价格、包装、尺寸、装卸货等信息|无货名</th>\n      <td>725</td>\n      <td>725</td>\n      <td>725</td>\n      <td>725</td>\n      <td>725</td>\n      <td>725</td>\n      <td>725</td>\n      <td>725</td>\n    </tr>\n    <tr>\n      <th>包含数量、价格、包装、尺寸、装卸货等信息|无货名|多个货物</th>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n    </tr>\n    <tr>\n      <th>包含数量、价格、包装、尺寸、装卸货等信息|货类</th>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n    </tr>\n    <tr>\n      <th>包含数量、价格、包装、尺寸、装卸货等信息|错字或拼音</th>\n      <td>84</td>\n      <td>84</td>\n      <td>84</td>\n      <td>84</td>\n      <td>84</td>\n      <td>84</td>\n      <td>84</td>\n      <td>84</td>\n    </tr>\n    <tr>\n      <th>危险品/危化品/违禁词</th>\n      <td>109</td>\n      <td>109</td>\n      <td>109</td>\n      <td>109</td>\n      <td>109</td>\n      <td>109</td>\n      <td>109</td>\n      <td>109</td>\n    </tr>\n    <tr>\n      <th>多个货物</th>\n      <td>15212</td>\n      <td>15212</td>\n      <td>15212</td>\n      <td>15212</td>\n      <td>15212</td>\n      <td>15212</td>\n      <td>15212</td>\n      <td>15212</td>\n    </tr>\n    <tr>\n      <th>多个货物|包含数量、价格、包装、尺寸、装卸货等信息</th>\n      <td>99</td>\n      <td>99</td>\n      <td>99</td>\n      <td>99</td>\n      <td>99</td>\n      <td>99</td>\n      <td>99</td>\n      <td>99</td>\n    </tr>\n    <tr>\n      <th>多个货物|包含数量、价格、包装、尺寸、装卸货等信息|无货名</th>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n    </tr>\n    <tr>\n      <th>多个货物|无货名</th>\n      <td>6</td>\n      <td>6</td>\n      <td>6</td>\n      <td>6</td>\n      <td>6</td>\n      <td>6</td>\n      <td>6</td>\n      <td>6</td>\n    </tr>\n    <tr>\n      <th>多个货物|错字或拼音</th>\n      <td>6</td>\n      <td>6</td>\n      <td>6</td>\n      <td>6</td>\n      <td>6</td>\n      <td>6</td>\n      <td>6</td>\n      <td>6</td>\n    </tr>\n    <tr>\n      <th>无货名</th>\n      <td>17744</td>\n      <td>17744</td>\n      <td>17744</td>\n      <td>17744</td>\n      <td>17744</td>\n      <td>17744</td>\n      <td>17744</td>\n      <td>17744</td>\n    </tr>\n    <tr>\n      <th>无货名|包含数量、价格、包装、尺寸、装卸货等信息</th>\n      <td>283</td>\n      <td>283</td>\n      <td>283</td>\n      <td>283</td>\n      <td>283</td>\n      <td>283</td>\n      <td>283</td>\n      <td>283</td>\n    </tr>\n    <tr>\n      <th>无货名|包含数量、价格、包装、尺寸、装卸货等信息|多个货物</th>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n    </tr>\n    <tr>\n      <th>无货名|包含数量、价格、包装、尺寸、装卸货等信息|错字或拼音</th>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n    </tr>\n    <tr>\n      <th>无货名|危险品/危化品/违禁词</th>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n    </tr>\n    <tr>\n      <th>无货名|多个货物</th>\n      <td>5</td>\n      <td>5</td>\n      <td>5</td>\n      <td>5</td>\n      <td>5</td>\n      <td>5</td>\n      <td>5</td>\n      <td>5</td>\n    </tr>\n    <tr>\n      <th>无货名|多个货物|包含数量、价格、包装、尺寸、装卸货等信息</th>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n    </tr>\n    <tr>\n      <th>无货名|错字或拼音</th>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n    </tr>\n    <tr>\n      <th>货类</th>\n      <td>597</td>\n      <td>597</td>\n      <td>597</td>\n      <td>597</td>\n      <td>597</td>\n      <td>597</td>\n      <td>597</td>\n      <td>597</td>\n    </tr>\n    <tr>\n      <th>货类|包含数量、价格、包装、尺寸、装卸货等信息</th>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n    </tr>\n    <tr>\n      <th>错字或拼音</th>\n      <td>4302</td>\n      <td>4302</td>\n      <td>4302</td>\n      <td>4302</td>\n      <td>4302</td>\n      <td>4302</td>\n      <td>4302</td>\n      <td>4302</td>\n    </tr>\n    <tr>\n      <th>错字或拼音|包含数量、价格、包装、尺寸、装卸货等信息</th>\n      <td>92</td>\n      <td>92</td>\n      <td>92</td>\n      <td>92</td>\n      <td>92</td>\n      <td>92</td>\n      <td>92</td>\n      <td>92</td>\n    </tr>\n    <tr>\n      <th>错字或拼音|危险品/危化品/违禁词</th>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n    </tr>\n    <tr>\n      <th>错字或拼音|多个货物</th>\n      <td>5</td>\n      <td>5</td>\n      <td>5</td>\n      <td>5</td>\n      <td>5</td>\n      <td>5</td>\n      <td>5</td>\n      <td>5</td>\n    </tr>\n    <tr>\n      <th>错字或拼音|多个货物|包含数量、价格、包装、尺寸、装卸货等信息</th>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n    </tr>\n    <tr>\n      <th>错字或拼音|无货名</th>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n    </tr>\n    <tr>\n      <th>错字或拼音|货类</th>\n      <td>2</td>\n      <td>2</td>\n      <td>2</td>\n      <td>2</td>\n      <td>2</td>\n      <td>2</td>\n      <td>2</td>\n      <td>2</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "origin_df.groupby([\"reason_text\"]).count()"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "outputs": [
    {
     "data": {
      "text/plain": "array(['1001', '1004|1001', '1001|1004', '1003', '1002', '1003|1001',\n       '1001|1003', '1004', '1002|1001', '1002|1003', '1001|1002',\n       '1001|1003|1002', '1003|1002', '1004|1002', '1002|1001|1003',\n       '1003|1001|1002', '1002|1004', '1003|1001|1004', '1003|1004',\n       '1003|1002|1001', '1004|1003', '1004|1002|1001', '1006', '1005',\n       '1004|1006', '1003|1005', '1004|1005', '1006|1001', '1001|1006'],\n      dtype=object)"
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "origin_df[\"reason_id\"].unique()"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "outputs": [
    {
     "data": {
      "text/plain": "       41540\n玉米       569\n小麦       304\n石子       186\n煤炭       177\n       ...  \n猪小肠        1\n铁箱子        1\n吕圈         1\n钢压块        1\n小电机        1\nName: core_word, Length: 4635, dtype: int64"
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "e = origin_df['core_word'].value_counts()\n",
    "e"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "outputs": [
    {
     "ename": "TypeError",
     "evalue": "Cannot reset_index inplace on a Series to create a DataFrame",
     "output_type": "error",
     "traceback": [
      "\u001B[1;31m---------------------------------------------------------------------------\u001B[0m",
      "\u001B[1;31mTypeError\u001B[0m                                 Traceback (most recent call last)",
      "Input \u001B[1;32mIn [13]\u001B[0m, in \u001B[0;36m<module>\u001B[1;34m\u001B[0m\n\u001B[0;32m      2\u001B[0m     \u001B[38;5;28;01mreturn\u001B[39;00m \u001B[38;5;124m\"\u001B[39m\u001B[38;5;124m$$\u001B[39m\u001B[38;5;124m\"\u001B[39m\u001B[38;5;241m.\u001B[39mjoin(df\u001B[38;5;241m.\u001B[39mvalues)\n\u001B[0;32m      3\u001B[0m df \u001B[38;5;241m=\u001B[39m origin_df\u001B[38;5;241m.\u001B[39mgroupby([\u001B[38;5;124m'\u001B[39m\u001B[38;5;124mcore_word\u001B[39m\u001B[38;5;124m'\u001B[39m])[\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mbad_case_name\u001B[39m\u001B[38;5;124m\"\u001B[39m]\u001B[38;5;241m.\u001B[39mapply(join)\n\u001B[1;32m----> 5\u001B[0m df \u001B[38;5;241m=\u001B[39m  \u001B[43mdf\u001B[49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mreset_index\u001B[49m\u001B[43m(\u001B[49m\u001B[43minplace\u001B[49m\u001B[38;5;241;43m=\u001B[39;49m\u001B[38;5;28;43;01mTrue\u001B[39;49;00m\u001B[43m)\u001B[49m\n\u001B[0;32m      6\u001B[0m df\n",
      "File \u001B[1;32mD:\\Users\\fengfeng.qiu\\Anaconda3\\envs\\Validate\\lib\\site-packages\\pandas\\util\\_decorators.py:311\u001B[0m, in \u001B[0;36mdeprecate_nonkeyword_arguments.<locals>.decorate.<locals>.wrapper\u001B[1;34m(*args, **kwargs)\u001B[0m\n\u001B[0;32m    305\u001B[0m \u001B[38;5;28;01mif\u001B[39;00m \u001B[38;5;28mlen\u001B[39m(args) \u001B[38;5;241m>\u001B[39m num_allow_args:\n\u001B[0;32m    306\u001B[0m     warnings\u001B[38;5;241m.\u001B[39mwarn(\n\u001B[0;32m    307\u001B[0m         msg\u001B[38;5;241m.\u001B[39mformat(arguments\u001B[38;5;241m=\u001B[39marguments),\n\u001B[0;32m    308\u001B[0m         \u001B[38;5;167;01mFutureWarning\u001B[39;00m,\n\u001B[0;32m    309\u001B[0m         stacklevel\u001B[38;5;241m=\u001B[39mstacklevel,\n\u001B[0;32m    310\u001B[0m     )\n\u001B[1;32m--> 311\u001B[0m \u001B[38;5;28;01mreturn\u001B[39;00m func(\u001B[38;5;241m*\u001B[39margs, \u001B[38;5;241m*\u001B[39m\u001B[38;5;241m*\u001B[39mkwargs)\n",
      "File \u001B[1;32mD:\\Users\\fengfeng.qiu\\Anaconda3\\envs\\Validate\\lib\\site-packages\\pandas\\core\\series.py:1488\u001B[0m, in \u001B[0;36mSeries.reset_index\u001B[1;34m(self, level, drop, name, inplace)\u001B[0m\n\u001B[0;32m   1484\u001B[0m         \u001B[38;5;28;01mreturn\u001B[39;00m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39m_constructor(\n\u001B[0;32m   1485\u001B[0m             \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39m_values\u001B[38;5;241m.\u001B[39mcopy(), index\u001B[38;5;241m=\u001B[39mnew_index\n\u001B[0;32m   1486\u001B[0m         )\u001B[38;5;241m.\u001B[39m__finalize__(\u001B[38;5;28mself\u001B[39m, method\u001B[38;5;241m=\u001B[39m\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mreset_index\u001B[39m\u001B[38;5;124m\"\u001B[39m)\n\u001B[0;32m   1487\u001B[0m \u001B[38;5;28;01melif\u001B[39;00m inplace:\n\u001B[1;32m-> 1488\u001B[0m     \u001B[38;5;28;01mraise\u001B[39;00m \u001B[38;5;167;01mTypeError\u001B[39;00m(\n\u001B[0;32m   1489\u001B[0m         \u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mCannot reset_index inplace on a Series to create a DataFrame\u001B[39m\u001B[38;5;124m\"\u001B[39m\n\u001B[0;32m   1490\u001B[0m     )\n\u001B[0;32m   1491\u001B[0m \u001B[38;5;28;01melse\u001B[39;00m:\n\u001B[0;32m   1492\u001B[0m     \u001B[38;5;28;01mif\u001B[39;00m name \u001B[38;5;129;01mis\u001B[39;00m lib\u001B[38;5;241m.\u001B[39mno_default:\n\u001B[0;32m   1493\u001B[0m         \u001B[38;5;66;03m# For backwards compatibility, keep columns as [0] instead of\u001B[39;00m\n\u001B[0;32m   1494\u001B[0m         \u001B[38;5;66;03m#  [None] when self.name is None\u001B[39;00m\n",
      "\u001B[1;31mTypeError\u001B[0m: Cannot reset_index inplace on a Series to create a DataFrame"
     ]
    }
   ],
   "source": [
    "def join(df):\n",
    "    return \"$$\".join(df.values)\n",
    "df = origin_df.groupby(['core_word'])[\"bad_case_name\"].apply(join)\n",
    "\n",
    "df =  df.reset_index(inplace=True)\n",
    "df"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [
    "pd.merge(df,g,on='core_word')"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [
    "h = origin_df.groupby(['core_word'])[\"bad_case_name\"].count()\n",
    "h = h.to_frame()\n",
    "h\n"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'h' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001B[1;31m---------------------------------------------------------------------------\u001B[0m",
      "\u001B[1;31mNameError\u001B[0m                                 Traceback (most recent call last)",
      "Input \u001B[1;32mIn [14]\u001B[0m, in \u001B[0;36m<module>\u001B[1;34m\u001B[0m\n\u001B[1;32m----> 1\u001B[0m pd\u001B[38;5;241m.\u001B[39mmerge(\u001B[43mh\u001B[49m,df,on\u001B[38;5;241m=\u001B[39m\u001B[38;5;124m'\u001B[39m\u001B[38;5;124mcore_word\u001B[39m\u001B[38;5;124m'\u001B[39m)\n",
      "\u001B[1;31mNameError\u001B[0m: name 'h' is not defined"
     ]
    }
   ],
   "source": [
    "pd.merge(h,df,on='core_word')"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'h' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001B[1;31m---------------------------------------------------------------------------\u001B[0m",
      "\u001B[1;31mNameError\u001B[0m                                 Traceback (most recent call last)",
      "Input \u001B[1;32mIn [15]\u001B[0m, in \u001B[0;36m<module>\u001B[1;34m\u001B[0m\n\u001B[1;32m----> 1\u001B[0m pd\u001B[38;5;241m.\u001B[39mconcat([\u001B[43mh\u001B[49m,df],keys\u001B[38;5;241m=\u001B[39m\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mcore_word\u001B[39m\u001B[38;5;124m\"\u001B[39m)\n",
      "\u001B[1;31mNameError\u001B[0m: name 'h' is not defined"
     ]
    }
   ],
   "source": [
    "pd.concat([h,df],keys=\"core_word\")"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}